﻿using Server.MessageModule.Message;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.MessageModule.MessageProcessor
{
    class NetworkMessageFactory
    {
        public static BaseNetworkMessage createNetworkMessage(string type)
        {
            BaseNetworkMessage result = null;
            switch (type)
            {
                case ShareMacro.MESSAGETYPE_COMMAND:
                    result = new CommandMessage();
                    break;
                default:
                    break;
            }
            return result;
        }

        public static INetworkMessage messageFromJson(String json)
        {
            INetworkMessage baseMsg = new BaseNetworkMessage(null);
            baseMsg.Deserialize(json);
            switch (baseMsg.getType())
            {
                case ShareMacro.MESSAGETYPE_COMMAND:
                    baseMsg = new CommandMessage();
                    baseMsg.Deserialize(json);
                    break;
                case ShareMacro.MESSAGETYPE_SENSOR:
                    baseMsg = new SensorMessage();
                    baseMsg.Deserialize(json);
                    break;
                default:
                    baseMsg = null;
                    break;
            }
            return baseMsg;
        }
    }
}
